package com.lg.online_shop.config;

import com.lg.online_shop.interceptors.LoginInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig  implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns("/index","/user/login","/admin/**","/user/register","/user/getVerificationCode","/css/**","/js/**","/img/**","/icon/**","/swagger-ui/index.html");
    }

//    @Bean
//    public WebMvcConfigurer corsConfigurer() {
//        return new WebMvcConfigurer() {
//            @Override
//            public void addCorsMappings(CorsRegistry registry) {
//                registry.addMapping("/**") // 允许所有路径
//                        .allowedOrigins("http://localhost:5173") // 指定允许的来源
//                        .allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的 HTTP 方法
//                        .allowedHeaders("*") // 允许的请求头
//                        .allowCredentials(true); // 是否允许携带 Cookie
//            }
//        };
//    }
}
